package org.jsbd.boss.mq;

import org.jsbd.boss.domian.AppLogAction;
import org.jsbd.boss.domian.channel.SimulatorNewActionLog;
import org.jsbd.boss.domian.channel.SoUploadLog;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.webnion.log.api.bean.DbTaskBean;
import com.webnion.log.api.constant.DdNameConstant;

public class MqLogManager {
	public static final Logger LOGGER = LoggerFactory.getLogger(MqLogManager.class);

	public static final String WEB_LOG="webLog";
	
	public static final String CRACK_LOG="crackLog";
	
	public static void saveSoUploadLog(SoUploadLog log) {
		String tableName="qy_so_upload_log_"+log.getCurrentDate();
		addWebLog(tableName,JSON.toJSONString(log));
	}
	
	public static void saveNewActionLog(SimulatorNewActionLog log) {
		String tableName="qy_simulator_new_action_log_"+log.getCurrentDate();
		addWulijiLog(tableName,JSON.toJSONString(log));
	}
	
	public static void saveAppActionLog(AppLogAction appLogAction) {
		String tableName="qy_app_log_action_"+appLogAction.getCurrentDate();
		addWulijiLog(tableName,JSON.toJSONString(appLogAction));
	}
	
	public static void saveSdkLog(String data) {
		String tableName="qy_sdk_action_log_"+DateUtil.getCurrentDateStr();
		addWulijiLog(tableName,data);
	}

	public static void addWebLog(String tableName,String data) {
    	saveLog(WEB_LOG,tableName,data);
	}
	
	public static void addWulijiLog(String tableName,String data) {
    	saveLog(DdNameConstant.WULIJILOG,tableName,data);
	}
	
	public static void addCrackLog(String tableName,String data) {
    	saveLog(CRACK_LOG,tableName,data);
	}
    
    public static void saveLog(String dbName,String tableName,String data) {
    	DbTaskBean task=new DbTaskBean();
    	task.setData(data);
    	task.setDbName(dbName);
    	task.setTableName(tableName);
    	KafkaMqManager.saveLogToQueue(JSON.toJSONString(task));
    }
    
    public static void saveSoUploadLog(String data) {
    	DbTaskBean task=new DbTaskBean();
    	task.setData(data);
    	task.setDbName(WEB_LOG);
    	task.setTableName("qy_so_upload_error_log");
    	KafkaMqManager.saveLogToQueue(JSON.toJSONString(task));
    }
	
}
